//
//  ScreenSaverVC.swift
//  HLDesktop
//
//  Created by 黄龙 on 2023/10/11.
//

import UIKit

class ScreenSaverVC: UIViewController {
//    lazy var collectView: UICollectionView = {
//                // FlowLayout自定义设置
//        let layout = UICollectionViewFlowLayout.init()
//            // 设置item的排列方式 ( horizontal , vertical)
//        layout.scrollDirection = .vertical
//                // 设置item的size
//        let backW = screen_W - 20
//        let itemW = (backW-4*5) / 3
//        let itemH = itemW * screen_H/screen_W
//        layout.itemSize = CGSize(width:itemW , height: itemH)
////最小列间距
//        layout.minimumLineSpacing = 3
////最小行间距
//        layout.minimumInteritemSpacing = 3
////设置item的四边边距（四边边距不是每个item的内缩边距，而是外间隔连距，所以计算item大小时，还要将边距计算在内减掉边距后，再算item大小）
//        layout.sectionInset = UIEdgeInsets.init(top: 5, left: 5, bottom: 5, right: 5)
////设置页头尺寸
//        layout.headerReferenceSize = CGSize(width: backW, height: 0)
//
////设置页尾尺寸
//        layout.footerReferenceSize = CGSize(width: backW, height: 0)
//
//        // 初始化
//        let collectview = UICollectionView.init(frame: CGRect(x: 0, y: 0, width: backW, height: itemH), collectionViewLayout: layout)
//            // 设置背景颜色
//        collectview.backgroundColor = .systemGroupedBackground
//        // 设置代理对象
//        collectview.delegate = self
//        // 设置数据源对象
//        collectview.dataSource = self
//        collectview.showsVerticalScrollIndicator = false
//            // 设置垂直滚动是否滚到item的最底部
//        collectview.alwaysBounceVertical = true
//            // 设置水平滚动是否滚到item的最右边
////        collectview.alwaysBounceHorizontal = true
//            // 开启uicollectionView的分页显示效果
//        collectview.isPagingEnabled = false //与scrollview的分页类似,分页滑动，还是平滑
//
//        // 注册Cell
//        collectview.register(WallpaperCell.self, forCellWithReuseIdentifier: "ScreenSaverCell")
//        // 注册Hearder
////        collectview.register(SectionHeader.self, forSupplementaryViewOfKind:UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerIdentifier")
//
//        // 注册footer
////        collectview.register(UICollectionReusableView.self, forSupplementaryViewOfKind:UICollectionView.elementKindSectionFooter, withReuseIdentifier: "footIdentifier")
//
//        return collectview
//     }()
//
    
    deinit {
        print("没有循环引用，才会触发: ScreenSaverVC.deinit")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .systemGroupedBackground
        initView()
    }
    
    func initTopBar(_ topSpace:CGFloat){
        let topView = UIView(frame: CGRect(x: 0, y: 0, width: screen_W, height: topSpace))
        view.addSubview(topView)
        let lineH = CALayer()
        topView.layer.addSublayer(lineH)
        lineH.frame = CGRect(x: 0, y: topSpace-0.5, width: screen_W, height: 0.5)
        lineH.backgroundColor = UIColor.systemGray.withAlphaComponent(0.5).cgColor
        
        let titleLabel = UILabel(frame: CGRect(x: 0, y: topSpace - 48, width: screen_W, height: 48))
        topView.addSubview(titleLabel)
        titleLabel.font = .boldSystemFont(ofSize: 16)
        titleLabel.text = "屏保选择"
        titleLabel.textColor = .label
        titleLabel.textAlignment = .center
        
        let closeButton = UIButton(frame: CGRect(x: screen_W-48, y: topSpace-48, width: 48, height: 48))
        topView.addSubview(closeButton)
        closeButton.setImage(UIImage(named: "toolbar_close_1@2x.png"), for: .normal)
        closeButton.addActionWithBlock { [weak self](sender) in
            self?.dismiss(animated: true) //如果不用[weak self]，则关闭窗口时就不会执行到析构deinit
        }
    }

    func initView(){
        let topSpace = UIDevice.ui_navigationFullHeight()
        self.initTopBar(topSpace)
        
        let btnWidth = screen_W-60
        let iTop = topSpace+20.0
        let albumBtn = UIButton(frame: CGRect(x: 30, y: iTop, width: btnWidth, height: 42))
        view.addSubview(albumBtn)
        albumBtn.setTitle("  从手机相册选择", for: .normal)
        albumBtn.setImage(UIImage(named: "albumBtn@2x.png"), for: .normal)
        albumBtn.setTitleColor(prjTitleColor, for: .normal)
        albumBtn.easyRoundRect(corner: [.topLeft,.topRight], radii: CGSize(width: 6, height: 6))
        albumBtn.backgroundColor = prjTitleColor.withAlphaComponent(0.75)
        albumBtn.addActionWithBlock { sender in
        }

//        view.addSubview(self.collectView)
//        collectView.frame = CGRect(x: 10, y: iTop, width: screen_W-20, height: screen_H - iTop)
//        self.initDataAtPage(0)
    }

}

//extension ScreenSaverVC:UICollectionViewDelegate{
//    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
////        let iRow = indexPath.row
////        iTapPaperIndex = iRow
////        showPaperReview(iRow)
//    }
//
//    func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
//        return true
//    }
//}
//
//extension ScreenSaverVC:UICollectionViewDataSource{
//    // 设置组数
//    func numberOfSections(in collectionView: UICollectionView) -> Int {
//        return 1
//    }
//
//    // 设置每组item个数
//    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//        return 0
//    }
//
//    // 注册cell
//    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//        let cellString = "ScreenSaverCell"
//        if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellString, for: indexPath) as? WallpaperCell{
////            let tmpName = localPapers[indexPath.row]
////            cell.updateGifCell(imgName: tmpName)
//            return cell
//        }
//     
//        return UICollectionViewCell()
//    }
//}
